﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

namespace PHTShop.admin
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
       
        }
        

        
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            
            string user = txtusername.Value;
            string pass = FormsAuthentication.HashPasswordForStoringInConfigFile(txtpassword.Value, "SHA1");
            Account admin=null;
           
                try
                {
                    admin = new DataContextDataContext().Accounts.Single(acc => acc.username.Equals(user) && acc.password.Equals(pass));
                    if (admin != null )
                    {
                        if (admin.active == true)
                        {
                            Session["admin"] = admin;
                            Response.Redirect("index.aspx");
                        }
                       
                    }
                    
                }
                catch (Exception)
                {
                    
                }
        }
    }
}